Repository navigation
feat(HikVision): integrate WebRTC preview with MediaMTX - #1389
Conversation
Reviewer's GuideAPIReplace the WebRTC component’s direct player-URL parameter with camera options and inject the MediaMTX service, changing the public integration contract.
Clarify the HikVision WebSDK component’s public login, channel callback, capture, and window-layout behavior.
ImplementationInitialize the MediaMTX gateway and register the camera on first interactive render, handle failures and cancellation, then construct and validate the player URL and cancel outstanding work on disposal.
UIRender localized missing-options, initialization, failure, and invalid-URL states, and show the iframe only when a player URL is available.
ConfigurationUpdate the HikVision package’s MediaMTX dependency, package version, platform support, and locale resource embedding configuration.
DocumentationAdd package setup, server-side WebRTC deployment, security, and WebSDK usage guidance in the README.
Revise the bundled skill reference to describe the new MediaMTX-backed component contract, operational behavior, and deployment guidance.
Correct the XML documentation for digital and zero-channel model types.
Lock files and vendored codeAdd English and Chinese localized strings for the WebRTC component’s status and error states.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Linked issuesChecked at commit ad7fce7 #1388 feat(HikVision): integrate WebRTC preview with MediaMTX · 6 of 6 met
|
There was a problem hiding this comment.
Hey - I've found 8 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="139" />
<code_context>
+ string? registeredUrl = null;
+ try
+ {
+ registeredUrl = await MediaMtxService.AddOrUpdateAsync(options, cancellationToken);
+ cancellationToken.ThrowIfCancellationRequested();
+ }
</code_context>
<issue_to_address>
**Camera streams lack reader authorization**
When the MediaMTX listener is reachable through a reverse proxy or other network route that does not enforce authentication, the registered camera is served through MediaMTX, whose generated configuration grants `read` permission to user `any`. An unauthenticated visitor who can reach the gateway or an unauthenticated reverse proxy can view streams by path, bypassing authorization on the page that renders this component.
Require authorization at the MediaMTX reader or reverse-proxy boundary before exposing camera streams, and document that page authorization alone does not protect the iframe endpoint.
</issue_to_address>
### Comment 2
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="139" />
<code_context>
+ string? registeredUrl = null;
+ try
+ {
+ registeredUrl = await MediaMtxService.AddOrUpdateAsync(options, cancellationToken);
+ cancellationToken.ThrowIfCancellationRequested();
+ }
</code_context>
<issue_to_address>
**Camera options enable server-side SSRF**
When an application lets an untrusted user choose or modify the component's `Options`, `RegisterUrl` passes the supplied camera options to the server-side MediaMTX service, which accepts any absolute RTSP/RTSPS host and lets MediaMTX connect to it. A user who can influence those options can make the application server connect to internal or otherwise restricted RTSP services.
Validate the RTSP destination against a server-side allowlist or equivalent network policy before registering it, and prevent access to loopback, link-local, and other restricted destinations.
</issue_to_address>
### Comment 3
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="25" />
<code_context>
/// </summary>
[Parameter]
- public string? WebRtcUrl { get; set; }
+ public MediaMtxCameraOptions? Options { get; set; }
/// <summary>
</code_context>
<issue_to_address>
**Existing consumers stop compiling**
When an application upgrades from 11.0.2 while still passing `WebRtcUrl`, `HikVisionWebRtc` no longer exposes `WebRtcUrl`, so existing Razor or C# usages fail to compile instead of working as a patch upgrade.
Keep `WebRtcUrl` compatible, or make its removal in a major release.
Also at `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs:26`.
</issue_to_address>
### Comment 4
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="155" />
<code_context>
private Uri? GetPlayerUrl()
{
- if (!Uri.TryCreate(WebRtcUrl, UriKind.Absolute, out var url) ||
+ if (!Uri.TryCreate(Options?.PlayUrl ?? _registeredUrl, UriKind.Absolute, out var url) ||
url.Scheme is not ("http" or "https") || url.UserInfo.Length != 0)
{
</code_context>
<issue_to_address>
**Preview switches to unregistered camera**
When the parent changes `Options.PlayUrl` after initial registration, including while gateway startup is awaited, `GetPlayerUrl` reads the latest `Options.PlayUrl`, while registration uses the options captured during initialization, so the iframe points to a source that is not registered and the preview shows the wrong camera or fails.
Register the updated options when they change, or have the iframe use only the URL corresponding to the registered options.
</issue_to_address>
### Comment 5
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="139" />
<code_context>
+ string? registeredUrl = null;
+ try
+ {
+ registeredUrl = await MediaMtxService.AddOrUpdateAsync(options, cancellationToken);
+ cancellationToken.ThrowIfCancellationRequested();
+ }
</code_context>
<issue_to_address>
**Closed previews leave registrations**
When a preview component is removed after registering a path that is not intended to remain available, each successful `RegisterUrl` call adds or updates a path in the shared gateway, but disposing the component only cancels pending work and never calls `RemoveAsync`; applications that create previews for transient or changing paths leave stale path configuration and its source credentials active until explicitly removed or the gateway stops.
Define ownership and cleanup semantics for component-created registrations, such as an explicit opt-in cleanup policy or a documented caller-managed registration lifecycle.
</issue_to_address>
### Comment 6
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="92" />
<code_context>
+ var started = await TryEnsureStartedAsync(cancellationToken);
+ if (started)
+ {
+ _registeredUrl = await RegisterUrl(options, cancellationToken);
+ }
+ }
</code_context>
<issue_to_address>
**Restart leaves preview failed**
When a component's startup check returns just before the gateway exits, and another component restarts it while the first proceeds to register, `RegisterUrl` calls `AddOrUpdateAsync` during the restart gap; the service has cleared its API password, so registration throws. `RegisterUrl` catches the exception and leaves `_registeredUrl` null, and this first-render-only initialization then displays a registration error even after the gateway recovers.
Coordinate registration with gateway restart, or retry startup and registration when the service reports that the gateway is not running.
</issue_to_address>
### Comment 7
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="148" />
<code_context>
+ }
+ catch (Exception ex)
+ {
+ Log.LogError(ex, "Failed to register the camera for WebRTC preview. Check the camera path and RTSP URL.");
+ }
+ return registeredUrl;
</code_context>
<issue_to_address>
**Invalid URLs show registration error**
When the default MediaMTX service receives an invalid `Options.PlayUrl`, `RegisterUrl` catches the service exception and leaves `_registeredUrl` null, so the markup shows `RegistrationFailedText` before checking `PlayerUrl` and users see a registration error instead of the invalid-URL message.
Preserve or set the invalid-URL failure state when registration rejects `PlayUrl`, and render that message instead of the generic registration error.
Also at `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor:17`.
</issue_to_address>
### Comment 8
<location path="src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs" line_range="134" />
<code_context>
+ return started;
+ }
+
+ private async Task<string?> RegisterUrl(MediaMtxCameraOptions options, CancellationToken cancellationToken)
+ {
+ string? registeredUrl = null;
</code_context>
<issue_to_address>
**Async helper misses naming suffix**
The private `RegisterUrl` method is asynchronous but lacks the `Async` suffix, so it violates the repository’s naming convention for async methods.
Rename `RegisterUrl` to `RegisterUrlAsync` and update its call site.
</issue_to_address>| string? registeredUrl = null; | ||
| try | ||
| { | ||
| registeredUrl = await MediaMtxService.AddOrUpdateAsync(options, cancellationToken); |
There was a problem hiding this comment.
🟠 High · Camera streams lack reader authorization
When the MediaMTX listener is reachable through a reverse proxy or other network route that does not enforce authentication, the registered camera is served through MediaMTX, whose generated configuration grants read permission to user any. An unauthenticated visitor who can reach the gateway or an unauthenticated reverse proxy can view streams by path, bypassing authorization on the page that renders this component.
Require authorization at the MediaMTX reader or reverse-proxy boundary before exposing camera streams, and document that page authorization alone does not protect the iframe endpoint.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 139:
**Camera streams lack reader authorization**
When the MediaMTX listener is reachable through a reverse proxy or other network route that does not enforce authentication, the registered camera is served through MediaMTX, whose generated configuration grants `read` permission to user `any`. An unauthenticated visitor who can reach the gateway or an unauthenticated reverse proxy can view streams by path, bypassing authorization on the page that renders this component.
Require authorization at the MediaMTX reader or reverse-proxy boundary before exposing camera streams, and document that page authorization alone does not protect the iframe endpoint.| string? registeredUrl = null; | ||
| try | ||
| { | ||
| registeredUrl = await MediaMtxService.AddOrUpdateAsync(options, cancellationToken); |
There was a problem hiding this comment.
🟠 High · Camera options enable server-side SSRF
When an application lets an untrusted user choose or modify the component's Options, RegisterUrl passes the supplied camera options to the server-side MediaMTX service, which accepts any absolute RTSP/RTSPS host and lets MediaMTX connect to it. A user who can influence those options can make the application server connect to internal or otherwise restricted RTSP services.
Validate the RTSP destination against a server-side allowlist or equivalent network policy before registering it, and prevent access to loopback, link-local, and other restricted destinations.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 139:
**Camera options enable server-side SSRF**
When an application lets an untrusted user choose or modify the component's `Options`, `RegisterUrl` passes the supplied camera options to the server-side MediaMTX service, which accepts any absolute RTSP/RTSPS host and lets MediaMTX connect to it. A user who can influence those options can make the application server connect to internal or otherwise restricted RTSP services.
Validate the RTSP destination against a server-side allowlist or equivalent network policy before registering it, and prevent access to loopback, link-local, and other restricted destinations.| /// </summary> | ||
| [Parameter] | ||
| public string? WebRtcUrl { get; set; } | ||
| public MediaMtxCameraOptions? Options { get; set; } |
There was a problem hiding this comment.
🟠 High · Existing consumers stop compiling
When an application upgrades from 11.0.2 while still passing WebRtcUrl, HikVisionWebRtc no longer exposes WebRtcUrl, so existing Razor or C# usages fail to compile instead of working as a patch upgrade.
Keep WebRtcUrl compatible, or make its removal in a major release.
Also at src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs:26.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 25:
**Existing consumers stop compiling**
When an application upgrades from 11.0.2 while still passing `WebRtcUrl`, `HikVisionWebRtc` no longer exposes `WebRtcUrl`, so existing Razor or C# usages fail to compile instead of working as a patch upgrade.
Keep `WebRtcUrl` compatible, or make its removal in a major release.
Also at `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs:26`.From docs/agents/component-checklist.md L5:
保留已有调用方式和所支持框架的行为。| private Uri? GetPlayerUrl() | ||
| { | ||
| if (!Uri.TryCreate(WebRtcUrl, UriKind.Absolute, out var url) || | ||
| if (!Uri.TryCreate(Options?.PlayUrl ?? _registeredUrl, UriKind.Absolute, out var url) || |
There was a problem hiding this comment.
🟡 Medium · Preview switches to unregistered camera
When the parent changes Options.PlayUrl after initial registration, including while gateway startup is awaited, GetPlayerUrl reads the latest Options.PlayUrl, while registration uses the options captured during initialization, so the iframe points to a source that is not registered and the preview shows the wrong camera or fails.
Register the updated options when they change, or have the iframe use only the URL corresponding to the registered options.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 155:
**Preview switches to unregistered camera**
When the parent changes `Options.PlayUrl` after initial registration, including while gateway startup is awaited, `GetPlayerUrl` reads the latest `Options.PlayUrl`, while registration uses the options captured during initialization, so the iframe points to a source that is not registered and the preview shows the wrong camera or fails.
Register the updated options when they change, or have the iframe use only the URL corresponding to the registered options.| string? registeredUrl = null; | ||
| try | ||
| { | ||
| registeredUrl = await MediaMtxService.AddOrUpdateAsync(options, cancellationToken); |
There was a problem hiding this comment.
🟡 Medium · Closed previews leave registrations
When a preview component is removed after registering a path that is not intended to remain available, each successful RegisterUrl call adds or updates a path in the shared gateway, but disposing the component only cancels pending work and never calls RemoveAsync; applications that create previews for transient or changing paths leave stale path configuration and its source credentials active until explicitly removed or the gateway stops.
Define ownership and cleanup semantics for component-created registrations, such as an explicit opt-in cleanup policy or a documented caller-managed registration lifecycle.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 139:
**Closed previews leave registrations**
When a preview component is removed after registering a path that is not intended to remain available, each successful `RegisterUrl` call adds or updates a path in the shared gateway, but disposing the component only cancels pending work and never calls `RemoveAsync`; applications that create previews for transient or changing paths leave stale path configuration and its source credentials active until explicitly removed or the gateway stops.
Define ownership and cleanup semantics for component-created registrations, such as an explicit opt-in cleanup policy or a documented caller-managed registration lifecycle.| var started = await TryEnsureStartedAsync(cancellationToken); | ||
| if (started) | ||
| { | ||
| _registeredUrl = await RegisterUrl(options, cancellationToken); |
There was a problem hiding this comment.
🟡 Medium · Restart leaves preview failed
When a component's startup check returns just before the gateway exits, and another component restarts it while the first proceeds to register, RegisterUrl calls AddOrUpdateAsync during the restart gap; the service has cleared its API password, so registration throws. RegisterUrl catches the exception and leaves _registeredUrl null, and this first-render-only initialization then displays a registration error even after the gateway recovers.
Coordinate registration with gateway restart, or retry startup and registration when the service reports that the gateway is not running.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 92:
**Restart leaves preview failed**
When a component's startup check returns just before the gateway exits, and another component restarts it while the first proceeds to register, `RegisterUrl` calls `AddOrUpdateAsync` during the restart gap; the service has cleared its API password, so registration throws. `RegisterUrl` catches the exception and leaves `_registeredUrl` null, and this first-render-only initialization then displays a registration error even after the gateway recovers.
Coordinate registration with gateway restart, or retry startup and registration when the service reports that the gateway is not running.| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.LogError(ex, "Failed to register the camera for WebRTC preview. Check the camera path and RTSP URL."); |
There was a problem hiding this comment.
🟡 Medium · Invalid URLs show registration error
When the default MediaMTX service receives an invalid Options.PlayUrl, RegisterUrl catches the service exception and leaves _registeredUrl null, so the markup shows RegistrationFailedText before checking PlayerUrl and users see a registration error instead of the invalid-URL message.
Preserve or set the invalid-URL failure state when registration rejects PlayUrl, and render that message instead of the generic registration error.
Also at src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor:17.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 148:
**Invalid URLs show registration error**
When the default MediaMTX service receives an invalid `Options.PlayUrl`, `RegisterUrl` catches the service exception and leaves `_registeredUrl` null, so the markup shows `RegistrationFailedText` before checking `PlayerUrl` and users see a registration error instead of the invalid-URL message.
Preserve or set the invalid-URL failure state when registration rejects `PlayUrl`, and render that message instead of the generic registration error.
Also at `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor:17`.| return started; | ||
| } | ||
|
|
||
| private async Task<string?> RegisterUrl(MediaMtxCameraOptions options, CancellationToken cancellationToken) |
There was a problem hiding this comment.
⚪ Low · Async helper misses naming suffix
The private RegisterUrl method is asynchronous but lacks the Async suffix, so it violates the repository’s naming convention for async methods.
Rename RegisterUrl to RegisterUrlAsync and update its call site.
Prompt for AI agents
In `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebRtc.razor.cs` at line 134:
**Async helper misses naming suffix**
The private `RegisterUrl` method is asynchronous but lacks the `Async` suffix, so it violates the repository’s naming convention for async methods.
Rename `RegisterUrl` to `RegisterUrlAsync` and update its call site.From AGENTS.md L18:
- **C#**。遵循 `.editorconfig` 和相邻文件的风格,优先使用文件范围命名空间,添加源文件时沿用文件头。源码启用可空引用类型和隐式 `using`。处理无效输入或已释放状态时可用早期返回,新增异步方法优先用 `Async` 后缀,保留已有公开签名和接口约定。[编辑器配置](.editorconfig) · [共享构建属性](Directory.Build.props)
Link issues
fixes #1388
Summary By Copilot
WebRtcUrlparameter withMediaMtxCameraOptions; on first interactive render, start the MediaMTX gateway and register the camera before displaying its player URL.BootstrapBlazor.HikVisionto 11.0.3, referenceBootstrapBlazor.MediaMtx11.0.1, mark the package as server-hosted rather than browser-supported, and embed the new locale resources.bb-hikvisionskill; adjust related component documentation.Regression?
The component API changes from
WebRtcUrltoOptions, so applications using the 11.0.2 API must migrate. This is an intentional change for the new server-side MediaMTX integration.Risk
The change affects a public component parameter and adds a server-side service dependency; existing direct-URL callers require migration, and this component is no longer suitable for standalone WebAssembly hosting.
Verification
Builds, tests, package generation, and browser playback checks were not run as required by the Issue/PR creation skill.
Packaging changes reviewed?
Reviewed the package version, MediaMTX package reference, browser platform exclusion, and embedded locale resources. Package generation/installation was not tested.
☑️ Self Check before Merge
The new README includes a server-side usage example, so a separate demo change was not needed. The branch includes the latest
mastercommit (a05389a4).Summary by Sourcery
Integrate HikVision WebRTC preview with MediaMTX camera registration and update the package contract for server-hosted use.
New Features:
Bug Fixes:
Enhancements:
Build:
Deployment:
Documentation: